<template>
  <div class="bar">
    <a-row :gutter="[8, 8]">
      <a-col :span="8">
        <div class="itemWrap">
          <div class="label"><span>返修单状态</span></div>
          <div class="separator"><span>:</span></div>
          <div class="content">
            <a-select
              v-model="search.statusList"
              mode="multiple"
              style="width: 100%;"
              :options="statusLists"
            >
            </a-select>
          </div>
        </div>
      </a-col>

      <a-col :span="4">
        <div class="itemWrap">
          <div class="label"><span>时间选择</span></div>
          <div class="separator"><span>:</span></div>
          <div class="content">
            <a-range-picker v-model="rangeTime" @change="onTimeChange" />
          </div>
        </div>
      </a-col>

      <a-col :span="4">
        <div class="itemWrap">
          <div class="label"><span>关键字</span></div>
          <div class="separator"><span>:</span></div>
          <div class="content">
            <a-input
              v-model="search.param"
              allow-clear
              placeholder="订单编号/产品型号/产品编号"
            />
          </div>
        </div>
      </a-col>

      <a-col :span="5">
        <div class="itemWrap">
          <a-button
            style="margin-left: 8px;"
            :type="search.isProcess ? 'primary' : ''"
            @click="search.isProcess = !search.isProcess"
          >
            <a-icon type="clock-circle" />待处理
          </a-button>
          <a-button
            style="margin-left: 8px;"
            :type="search.isStartUsername ? 'primary' : ''"
            @click="search.isStartUsername = !search.isStartUsername"
          >
            我发起的
          </a-button>
          <a-select
            class=""
            :default-value="search.warrantyStatus"
            :options="warrantyStatusLists"
            @change="handleWarrantyStatusChange"
            style="width: 80px;margin-left: 8px;"
          >
          </a-select>
        </div>
      </a-col>

      <a-col :span="3" push="0" style="text-align: right;">
        <!-- <a-button type="primary" style="margin-right: 8px;" @click="expandForm">
          <a-icon :type="expand ? 'left' : 'right'" />
        </a-button> -->
        <a-button
          type="primary"
          style="margin-right: 8px;"
          @click="searchData()"
        >
          搜索
        </a-button>
        <a-button type="primary" @click="restSearchData()">
          重置
        </a-button>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import locale from "ant-design-vue/es/date-picker/locale/zh_CN";
import api from "@/server/userConfig";
import { getRoleId } from "@/unit/tool";
import { RepairType } from "@/unit/constantValue";
import { WarrantyType } from "@/unit/constantValue";

export default {
  name: "ServiceStatistics",
  components: {},
  props: {
    initData: Object
  },
  data() {
    return {
      userName: "",
      name: "",
      role: "",
      compId: "",
      expand: false,
      rangeTime: [],
      statusLists: [],
      warrantyStatusLists: WarrantyType,
      search: {
        startTime: "",
        endTime: "",
        param: "",
        statusList: [],
        isProcess: false,
        isStartUsername: false,
        warrantyStatus: -1
      },
      defaultSearchData: ""
    };
  },
  methods: {
    // 选择保修类型;
    handleWarrantyStatusChange(value) {
      this.search.warrantyStatus = value;
    },

    buildTypeLists() {
      this.statusLists = RepairType;
    },

    buildDefaultData() {
      this.defaultSearchData = Object.assign({}, this.search);
    },

    onTimeChange(e) {
      let [startTime, endTime] = e;
      if (e.length > 0) {
        this.search.startTime = `${this.$Moment(startTime).format(
          "YYYY-MM-DD"
        )} 00:00:00`;
        this.search.endTime = `${this.$Moment(endTime).format(
          "YYYY-MM-DD"
        )} 23:59:59`;
      } else {
        this.search.startTime = "";
        this.search.endTime = "";
      }
    },

    expandForm() {
      this.expand = !this.expand;
    },
    searchData() {
      let _this = this;
      let { statusList, isStartUsername, ...restSearch } = this.search;
      let list = [].concat(statusList);
      if (statusList.indexOf(6) > -1) {
        list.push(11);
      }
      this.$emit("emitSearchData", {
        statusList: list,
        startUsername: isStartUsername ? _this.userName : "",
        ...restSearch
      });
    },
    restSearchData() {
      this.rangeTime = [];
      this.search = Object.assign({}, this.defaultSearchData);
    }
  },
  created() {},
  mounted() {
    getRoleId(this);
    this.buildTypeLists();
    this.buildDefaultData();
  },
  computed: {}
};
</script>

<style scoped="scoped">
.bar {
  width: 100%;
  background-color: #ffffff;
  border: 1px solid #e8e8e8;
  padding: 16px 16px 16px 16px;
}

.itemWrap {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-items: center;
}

.itemWrap > .label {
  min-width: 76px;
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #646464;
  text-align: right;
}

.itemWrap > .separator {
  padding: 0px 4px;
}

.itemWrap > .content {
  width: 100%;
  padding: 0px 1px;
}
</style>
